package com.xfs;

import net.minidev.json.JSONUtil;
import org.junit.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.util.DigestUtils;

/**
 * @Author dwj
 * @Date 2021-10-16 16:44
 */

public class MD5Utils {

    @Test
    public void test1(){
        // md5 Spring提供的加密方法，盐值自行处理
        String s1 = DigestUtils.md5DigestAsHex("123456".getBytes());
        System.out.println(s1);

        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String s2 = passwordEncoder.encode("123456");
        String s3 = passwordEncoder.encode("123456");
        System.out.println(s2);
        System.out.println(s3);


        // 验证
        boolean matches1 = passwordEncoder.matches("123456","$2a$10$fQso/C8CgAEqk9AhLElZKORDc4RzPptxU5/9ZqrofNJtb/WYcffMC");
        boolean matches2 = passwordEncoder.matches("123456","$2a$10$4.gu/EjvSf/JU71/UU4FVu3kEATZEOXWsJR5lGhx5T.skZm.0shGu");
        System.out.println(matches1+"\n"+matches2);
    }



}
